import 'dart:ui';

import 'package:cherry_toast/cherry_toast.dart';
import 'package:cherry_toast/resources/arrays.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:my_audio_recorder_example/Ext/ColorUtil.dart';

extension StringExt on String {
  /// String颜色值转Color
  Color toColor() {
    return ColorUtil.stringColor(this);
  }

  /// 打印String内容
  void toPrint() {
    print(this);
  }

  /// String转int
  int toInt() {
    try {
      return int.parse(this);
    } on Exception catch (e, s) {
      if (kDebugMode) {
        print('TEST=============================\n$s');
      }
      return 999999999999999999;
    }
  }

  void toastSuccess(BuildContext context) {
    CherryToast.success(
            displayIcon: true,
            disableToastAnimation: true,
            displayCloseButton: false,
            toastDuration: const Duration(milliseconds: 500),
            toastPosition: Position.top,
            borderRadius: 5,
            title: Text(this, style: const TextStyle(color: Colors.black)))
        .show(context);
  }

  void toastError(BuildContext context) {
    CherryToast.error(
            displayIcon: true,
            disableToastAnimation: true,
            displayCloseButton: false,
            toastDuration: const Duration(milliseconds: 500),
            toastPosition: Position.top,
            borderRadius: 5,
            title: Text(this, style: const TextStyle(color: Colors.black)))
        .show(context);
  }
}
